'use strict';
let mongoose = require('mongoose');

let schema = new mongoose.Schema({
    key: {
        type: String,
        required: true,
        index: {
            unique: true
        }
    },
    value:String
},{versionKey:false});

schema.statics = {
};

schema.methods={
    toVantJson(){
        let v=JSON.parse(this.value);
        let r={};
        for(let i=0;i<v.length;i++){
            r[v[i].name]={};
            for(let j=0;j<v[i].children.length;j++){
                r[v[i].name][v[i].children[j].name]=v[i].children[j].children;
            }
        }
        return r;
    }
};

module.exports = schema;